package com.test

import com.alibaba.fastjson.JSON
import org.apache.commons.httpclient.HttpClient
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils


/**
 * @Created by Orion
 * @Description
 */
object TestHttpClint {
  def main(args: Array[String]): Unit = {
     // 创建客户端  get  post
    val get = new HttpGet("https://restapi.amap.com/v3/geocode/regeo?output=json&location=116.393345,39.923568&key=daf1fca9fac7159400d99faf6ef74c74&radius=1000&extensions=bash")
    val httpClient = HttpClientBuilder.create().build()
   // 请求 接收数据
    val response = httpClient.execute(get)
    val entity = response.getEntity
    // 解析entity
    if (entity !=null){
      // 返回json数据
      val str = EntityUtils.toString(entity)
      // fastJson
      val nObject1 = JSON.parseObject(str)
      val address = nObject1.getJSONObject("regeocode").getJSONObject("addressComponent")
      val stree = nObject1.getJSONObject("regeocode").getString("formatted_address")

      val province = address.getString("province")
      val city = address.getString("city")
      val district = address.getString("district")

      println(stree)
    }


  }

}
